package com.hou.shardingjdbc.controller;

import com.github.pagehelper.PageInfo;
import com.hou.shardingjdbc.domain.BULID.OrderBuilder;
import com.hou.shardingjdbc.domain.PO.Order;
import com.hou.shardingjdbc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired private OrderService orderService;

    @GetMapping("/test")
    public String test(){
        return "hello world";
    }

    @GetMapping("/findAll")
    public PageInfo findAllOrderByPage(int currentPage, int pageSize){
        return null;
    }

    /**
     * 测试按照openid查询列表
     */
    @GetMapping("/findByOpenid")
    public List<Order> findByOpenid(String openid){
        return orderService.findByOpenid(openid);
    }


    /**
     *  测试查询count,对比数量,是否正确
     */
    @GetMapping("/count")
    public Integer selectCountByOpenid(String openid){
        return orderService.selectCountByOpenid(openid);
    }
    /**
     * 测试插入
     */
    @GetMapping("/insert")
    public void insertOrder(){
        Order order1 = OrderBuilder.create()
                .setOrderid(9527)
                .setOpenid("oFWgA5UDGu8BHuRHglcm9K4VXjck")
                .setPrice(199f)
                .setSdate("2019-06-01")
                .setEdate("2019-06-03")
                .build();
        System.out.println(order1);
        orderService.insertOrder(order1);
        Order order2 = OrderBuilder.create()
                .setOrderid(9528)
                .setOpenid("oFWgA5UDGu8BHuRHglcm9K4VXjck")
                .setPrice(199f)
                .setSdate("2019-06-01")
                .setEdate("2019-06-03")
                .build();
        System.out.println(order2);
        orderService.insertOrder(order2);
    }

}

